<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>实名认证</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../css/public.css" media="all">
				<style>
			body {
            	background-color: #ffffff;
        	}
    </style>
	</head>
	<body>
		<form class="layui-form layui-form-pane" lay-filter="myForm" id="app">		
									<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">姓名：</label>
					<div class="layui-input-block">
						<input v-model="detail.xingming" type="text" name="xingming" id="xingming" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">身份证：</label>
					<div class="layui-input-block">
						<input v-model="detail.shenfenzheng" type="text" name="shenfenzheng" id="shenfenzheng" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">手机号码：</label>
					<div class="layui-input-block">
						<input v-model="detail.shoujihaoma" type="text" name="shoujihaoma" id="shoujihaoma" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">年龄：</label>
					<div class="layui-input-block">
						<input v-model="detail.nianling" type="text" name="nianling" id="nianling" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<select name="xingbie" id="xingbie" lay-filter="xingbie">
							<option value="">请选择</option>
							<option v-for="(item,index) in xingbie" v-bind:key="index" :value="item">{{item}}</option>
						</select>
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">头像：</label>
					<div v-if="detail.touxiang" class="layui-input-block">
						<img id="touxiangImg" style="width: 91px;height: 91px;" :src="detail.touxiang">
						<input type="hidden" :value="detail.touxiang" id="touxiang" name="touxiang" />
					</div>
					<div class="layui-input-block">
						<button v-if="!corss"  type="button" class="layui-btn btn-theme" id="touxiangUpload">
							<i class="layui-icon">&#xe67c;</i>上传头像
						</button>
					</div>
				</div>
			</div>
												<div class="layui-col-xs12 layui-col-md6">
				<div class="layui-form-item" pane>
					<label class="layui-form-label">用户名：</label>
					<div class="layui-input-block">
						<input v-model="detail.yonghuming" type="text" name="yonghuming" id="yonghuming" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
																		
																																																			
			<div class="layui-form-item">
				<div class="layui-input-block" style="text-align: right;margin-right: 30px;">
					<button class="layui-btn btn-submit" lay-submit lay-filter="*">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>

		<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
		<script src="../../js/utils.js" charset="utf-8"></script>
		<script src="../../js/validate.js" charset="utf-8"></script>
		<script src="../../js/vue.js" charset="utf-8"></script>
		
		
		<script>
			var vue = new Vue({
				el: '#app',
				data: {
                    																																																		xingbie: [],
																																													detail: {
                                                                        xingming: '',
                                                                                                shenfenzheng: '',
                                                                                                shoujihaoma: '',
                                                                                                nianling: '',
                                                                                                xingbie: '',
                                                                                                touxiang: '',
                                                                                                yonghuming: '',
                                                                                                userid: '',
                                                                    },
					corss: false
				},
				updated: function() {
					layui.form.render('select', 'myForm');
				},
                computed: {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    },
				methods: {
					jump(url) {
						jump(url)
					}
				}
			})

			layui.use(['layer', 'element', 'carousel', 'jquery', 'form', 'upload', 'http' ,'laydate','tinymce'], function() {
				var layer = layui.layer;
				var element = layui.element;
				var carousel = layui.carousel;
				var http = layui.http;
				var jquery = layui.jquery;
				var form = layui.form;
				var upload = layui.upload;
				var laydate = layui.laydate;
                var tinymce = layui.tinymce

				
                																																								vue.xingbie = '男,女'.split(',')
																// 上传图片
				var touxiangUpload = upload.render({
					//绑定元素
					elem: '#touxiangUpload',
					//上传接口
					url: http.baseurl + 'file/upload',
					// 请求头
					headers: {
						Token: localStorage.getItem('Token')
					},
					// 允许上传时校验的文件类型
					accept: 'images',
					before: function() {
						//loading层
						var index = layer.load(1, {
							shade: [0.1, '#fff'] //0.1透明度的白色背景
						});
					},
					// 上传成功
					done: function(res) {
						console.log(res);
						layer.closeAll();
						if (res.code == 0) {
							layer.msg("上传成功", {
								time: 2000,
								icon: 6
							})
							var url = http.baseurl + 'upload/' + res.file;
							jquery('#touxiang').val(url);
							jquery('#touxiangImg').attr('src', url)
                            vue.detail.touxiang = url;
						} else {
							layer.msg(res.msg, {
								time: 2000,
								icon: 5
							})
						}
					},
					//请求异常回调
					error: function() {
						layer.closeAll();
						layer.msg("请求接口异常", {
							time: 2000,
							icon: 5
						})
					}
				});
																												
                                // session独取
				let table = localStorage.getItem("userTable");
				http.request(`${table}/session`, 'get', {}, function(data) {
					// 表单赋值
					//form.val("myForm", data.data);
					data = data.data
					for(var key in data){
						vue.detail[`${key}`] = data[`${key}`]
					}
					vue.detail[`userid`] = localStorage.getItem('userid')
				});
                
                // 跨表计算
                if(http.getParam('corss')){
					vue.corss = true
					var obj = JSON.parse(localStorage.getItem('crossObj'));
					for(var key in obj){
						vue.detail[`${key}`] = obj[`${key}`]
					}
				}
				
                																																																																
				// 提交
				form.on('submit(*)', function(data) {
					data = data.field;
                    // 数据校验
					                    					                                                                                                                                                                					                                                                                                                        if(!checkIdCard(data.shenfenzheng)){
                        layer.msg('身份证应输入身份证格式', {
							time: 2000,
							icon: 5
						});
                        return false
                    }
                                                                                					                                                                                                                                                                					                                        if(!isIntNumer(data.nianling)){
                        layer.msg('年龄应输入整数', {
							time: 2000,
							icon: 5
						});
                        return false
                    }
                                                                                                                                                                					                                                                                                                                                                					                                                                                                                                                                					                                                                                                                                                                					                                                                                                                                            
					// 跨表计算
					                                                                                                                                                                                                                                                                                                                                					
                    // 比较大小
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            					
					// 提交数据
					http.requestJson('shimingrenzheng' + '/save', 'post', data, function(res) {
					 	layer.msg('提交成功', {
					 		time: 2000,
					 		icon: 6
					 	}, function() {
					 		window.parent.location.reload();
						});
					 });

					return false
				});

			});
		</script>
	</body>
</html>
